﻿using RimWorld;
using Verse;

namespace RimZombieGirl
{
    public class HediffComp_CurseSadWander : HediffComp
    {
        private int lastMentalBreakDay = -1;

        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);

            Pawn pawn = this.Pawn;
            if (!pawn.RaceProps.Humanlike || !pawn.Spawned || pawn.Dead)
                return;

            if (Find.TickManager.TicksGame % 2500 != 0)
                return;

            int currentDay = GenLocalDate.DayOfYear(parent.pawn.Map);

            if (lastMentalBreakDay == currentDay)
                return;

            if (Rand.Value > 0.05f)
                return;

            if (pawn.mindState != null && pawn.mindState.mentalStateHandler != null)
            {
                if (pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Wander_Sad, "被诅咒折磨，陷入悲伤。".Translate(), forceWake: true))
                {
                    lastMentalBreakDay = currentDay;

                    Messages.Message($"{pawn.LabelShort} 因诅咒陷入了悲伤的徘徊。".Translate(), pawn, MessageTypeDefOf.NegativeEvent);
                }
            }
        }
    }

    public class HediffCompProperties_CurseSadWander : HediffCompProperties
    {
        public HediffCompProperties_CurseSadWander()
        {
            this.compClass = typeof(HediffComp_CurseSadWander);
        }
    }
}
